package com.wenx.ftpcamel;

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ModelCamelContext;

import java.io.File;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
 * Created by wenx on 2019-07-22 10:07
 */
public class FileTest2 {

    public static void main(String[] args) throws Exception {
        ModelCamelContext camelContext = new DefaultCamelContext();

        camelContext.start();

        camelContext.addRoutes(new RouteBuilder() {

            @Override
            public void configure() {
                from("quartz://825da6a0-7a77-49bf-8bbe-0301f0ee6957?cron=0 * * * * ? *&stateful=true")
                        .process(exchange -> {
//                            Stream<String> stream = Files.lines(Paths.get("E:\\test\\score.txt"));
//                            stream.forEach(System.out::println);
                            File file = new File("E:\\test\\score.txt");
                            FileInputStream fis = null;
                            fis = new FileInputStream(file);
                            System.out.println("Total file size to read (in bytes) : "
                                    + fis.available());
//                            int content;
//                            while ((content = fis.read()) != -1) {
//                                // convert to char and display it
//                                System.out.print((char) content);
//                            }
                            exchange.getOut().setHeader(Exchange.FILE_NAME,"dbaa.txt");
                            exchange.getOut().setBody(fis);
                        })
                        .to("file:D:\\test");
            }
        });

        synchronized (FileDemo1.class) {
            FileDemo1.class.wait();
        }
    }

}
